/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bussiness;

import dto.FolderMapping;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;

/**
 *
 * @author LW
 */
public class SendDataThread implements Runnable {
    private static int MAX_LENGTH = 10240;
    public void run() {

    }
    public boolean readFile(String path) throws FileNotFoundException, IOException, ClassNotFoundException{
        FileInputStream fins = new FileInputStream(path);
        ObjectInputStream ois = new ObjectInputStream(fins);
        Object obj = ois.readObject();
        FolderMapping fm = null;
        if(obj instanceof FolderMapping){
            fm = (FolderMapping) obj;
            
        }
        return true;
    }

    public void sendData(DataOutputStream output, FileInputStream fis) throws IOException{
        //File file = new File(filePath);
        //if(! file.exists()) return; //check exists this file

        //FileInputStream fis = null;
        BufferedInputStream bis = null;
        DataInputStream dis = null;

        try {
          //fis = new FileInputStream(file);

          // Here BufferedInputStream is added for fast reading.
          bis = new BufferedInputStream(fis);
          dis = new DataInputStream(bis);

          // dis.available() returns 0 if the file does not have more lines.
          int temp;
          while ((temp = dis.available()) != 0) {
            //System.out.println(dis.readLine());
            byte[] b = new byte[temp];
            dis.read(b);
            output.write(b);
          }

          // dispose all the resources after using them.
          fis.close();
          bis.close();
          dis.close();

        } catch (FileNotFoundException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
    }
}
